<?php

namespace app\admin\controller\place_order;

use app\common\controller\Backend;
use app\admin\model\Order as OrderModel;
use hehe\Trade;
use think\db\exception\PDOException;
use think\exception\ValidateException;
use think\facade\Config;
use think\facade\Db;
use Exception;

class Index extends Backend {
    protected object $model;

    // 排除字段
    protected array|string $preExcludeFields = ['updatetime', 'createtime'];

    protected array|string $quickSearchField = 'name';


    public function initialize():void {
        parent::initialize();
        $this->model = new OrderModel();
    }

    /**
     * 获取下单类型配置
     */
    public function getPlaceOrderTypeConfig(){
        $place_order_type = Config::get('custom.place_order_type');
        return $this->success('', [
            'list' => $place_order_type
        ]);
    }


    /**
     * 提交全部订单
     */
    public function subOrder():void {
        $data = $this->request->param();
        $where = [
            'user_id' => $data['user_id'],
            'draft' => 1
        ];
        $result = db::name('order')->where($where)->find();
        if(!$result) $this->error('没有待提交的订单');



        $update = [
            'out_trade_no' => Trade::generateTradeNo(),
            'place_order_time' => $this->timestamp,
            'draft' => 0
        ];
        $result = Db::name('order')->where($where)->update($update);
        if($result){
            $this->success();
        }else{
            $this->error();
        }
        print_r($data);die;
    }




}